package com.xuhuan.demo.pattern.decorator.decorator;

import com.xuhuan.demo.pattern.decorator.Drink;

/**
 * @author huan.xu
 * @date 2021/10/6 23:02
 * @description 调料
 */
public class Decorator extends Drink {

    private Drink coffee;

    public Decorator(Drink coffee) {
        this.coffee = coffee;
    }

    /**
     * 抽象方法，计算价格
     * super.getPrice()：自己的价格
     * coffee.getPrice()：咖啡的价格
     *
     * @return
     */
    @Override
    public float cost() {
        return super.getPrice() + coffee.cost();
    }

    @Override
    public String getDescription() {
        return super.getDescription() + " " + super.getPrice() + " && "
                + coffee.getDescription() ;
    }
}
